package com.thwj.project.app.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.thwj.common.annotation.Log;
import com.thwj.common.enums.BusinessType;
import com.thwj.framework.web.domain.R;
import com.thwj.framework.web.service.TokenService;
import com.thwj.project.app.api.param.UserAuthenticationParam;
import com.thwj.project.app.api.param.UserInfoParam;
import com.thwj.project.app.api.vo.UserAttentionVo;
import com.thwj.project.app.api.vo.UserAuthenticationVo;
import com.thwj.project.app.api.vo.UserFollowVo;
import com.thwj.project.app.api.vo.UserInfoVo;
import com.thwj.project.app.service.AppUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags="app 用户信息模块")
@RestController
@RequestMapping("/app/user")
public class AppUserController {


    @Autowired
    private TokenService tokenService;
    @Autowired
    private AppUserService appUserService;

    @ApiOperation(value = "获取当前登录用户信息",notes = "获取用户信息")
    @GetMapping("/getUserInfo")
    public R<UserInfoVo> getUserInfo() {
        UserInfoVo userInfoVo = appUserService.getUserInfo(tokenService.getLoginUser());
        return R.data(userInfoVo);
    }

    @ApiOperation(value = "获取个人主页用户信息",notes = "获取用户信息")
    @GetMapping("/getUserInfoByUserId")
    public R<UserInfoVo> getUserInfoByUserId(@RequestParam Long userId) {
        UserInfoVo userInfoVo = appUserService.getUserInfoByUserId(userId, tokenService.getLoginUser());
        return R.data(userInfoVo);
    }

    @ApiOperation(value = "更新用户信息",notes = "更新用户信息")
    @PostMapping("/updateUserInfo")
    public R<String> updateUserInfo(@RequestBody UserInfoParam userInfoParam) {
        appUserService.updateUserInfo(userInfoParam,tokenService.getLoginUser());
        return R.data("更新成功");
    }

    @Log(title = "用户认证", businessType = BusinessType.INSERT)
    @ApiOperation(value = "提交更新用户认证",notes = "提交更新用户认证 个人和俱乐部通用")
    @PostMapping("/saveUpdateUserAuthentication")
    public R<String> saveUpdateUserAuthentication(@RequestBody UserAuthenticationParam authenticationParam) {
        appUserService.saveUpdateUserAuthentication(authenticationParam, tokenService.getLoginUser());
        return R.data("已提交，等待后台审核");
    }

    @ApiOperation(value = "获取用户认证信息",notes = "获取用户认证信息")
    @PostMapping("/getUserAuthentication")
    public R<UserAuthenticationVo> getUserAuthentication() {
        UserAuthenticationVo userAuthenticationVo = appUserService.getUserAuthentication(tokenService.getLoginUser());
        return R.data(userAuthenticationVo);
    }

    @ApiOperation(value = "关注/取消关注",notes = "用户id为你要关注或者要取消关注的用户id")
    @PostMapping("/commitUserAttention")
    public R<String> commitUserAttention(@RequestParam Long userId) {
        appUserService.commitUserAttention(userId,tokenService.getLoginUser());
        return R.data("操作成功");
    }

    @ApiOperation(value = "获取个人用户关注分页列表",notes = "获取个人用户关注分页列表 如果是自己可以不穿用户id")
    @GetMapping("/getUserAttentionPage")
    public R<Page<UserAttentionVo>> getUserAttentionPage(Page page, @RequestParam(required = false) Long userId) {
        Page<UserAttentionVo> attentionPage = appUserService.getUserAttentionPage(page,userId,tokenService.getLoginUser());
        return R.data(attentionPage);
    }

    @ApiOperation(value = "获取个人用户粉丝分页列表",notes = "获取个人用户粉丝分页列表 如果是自己可以不穿用户id")
    @GetMapping("/getUserFollowPage")
    public R<Page<UserFollowVo>> getUserFollowPage(Page page, @RequestParam(required = false) Long userId) {
        Page<UserFollowVo> attentionPage = appUserService.getUserFollowPage(page,userId,tokenService.getLoginUser());
        return R.data(attentionPage);
    }


}
